/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package yinshi.util;

import java.util.ArrayList;

/**
 *
 * @author yinshi
 */
public class Tree<T> {

    private final Node root = new Node();

    public Tree() {
    }

    public Node<T> getRoot() {
        return root;
    }

    public void traverse(int type, Listener listener) {
    }

    public static class Node<T> {

        private T data;
        private final ArrayList<Node> children = new ArrayList<>();

        public T getData() {
            return data;
        }

        public void setData(T data) {
            this.data = data;
        }

        public int numOfChildren() {
            return children.size();
        }

        public Node getChild(int index) {
            return children.get(index);
        }

        public Node[] getChildren() {
            return children.toArray(new Node[0]);
        }

        public int createChild() {
            int index = children.size();
            children.add(new Node());
            return index;
        }

        public void clearChildren() {
            children.clear();
        }

        public boolean isLeaf() {
            return children.isEmpty();
        }
    }

    public static interface Listener {
    }
}
